package com.isprint.jslx.lcc.global.controller;

import com.isprint.jslx.base.controller.ControllerBase;
import com.isprint.jslx.lcc.Jfinal.LccJfinalConfig;
import com.isprint.jslx.lcc.config.Adminer;
import com.isprint.jslx.routes.RoutesProperties;
import com.jfinal.plugin.redis.Cache;
import com.jfinal.plugin.redis.Redis;
import com.kabao.ext.plugin.memcached.MemcachedKit;

/**
 * Created by ydw on 2017/7/14.
 */
public class GlobalController extends ControllerBase {
    Cache cache = Redis.use();
    @Override
    public void init() {
        this.setGLOBALATTRIBUTENAME(LccJfinalConfig.GLOBALUSERUUID);
        this.setROUTEPATH(RoutesProperties.ROUTES.get(this.getClass().getPackage().getName()+""));
    }
    /**
     * 获取当前登陆用户
     * @return admin or null
     */
    public Adminer getCurrentAdminer(){

        return ((Adminer) cache.get(this.getUUID()));
//        return (Adminer) MemcachedKit.getInstance().getObject(this.getUUID());
    }
    /**
     * 设置登陆
     * @param adminer
     */
    public void setCurrentAdminerToMemcached(Adminer adminer){
        cache.set(this.getUUID(),adminer);
//        MemcachedKit.getInstance().saveObject(this.getUUID(), adminer,null);
    }
    /**
     * 设置注销
     */
    public void removeCurrentAdminerToMemcached(){
        Long del = cache.del(this.getUUID());
        System.out.println(del);
    }
}
